package com.CGFrame.struts.bean.confirm;
import java.util.*;

import com.CGFrame.struts.POJOs.Confirmhistory;
import com.CGFrame.struts.POJOs.Make;
import com.CGFrame.struts.POJOs.Reguser;
import com.CGFrame.struts.POJOs.Task;
import com.CGFrame.struts.bean.ProjectOperate;
import com.CGFrame.struts.bean.ProjectOperateFactory;

public class ConfirmHistoryBean {

	public ConfirmHistoryBean()
	{
		
	}
	
	public void AddTaskConfirmHistory(String taskId,String regUserId,Short isPass ,String note)
	{
	
		ProjectOperate pop = ProjectOperateFactory.getprojectOperate();
		Reguser reguser = (Reguser)pop.UniqueQuery("Reguser", "regUserId,"+regUserId);
		Date date = new Date();
	//	System.out.println(date);
//		 java.sql.Date   sqlDate   =   new   java.sql.Date(date.getTime());   
	//	 System.out.println(sqlDate); 
		Confirmhistory confirmhistory = new Confirmhistory(reguser,"Task",Integer.parseInt(taskId),isPass,date,note);
		pop.saveObject(confirmhistory);
	}
	public List getTaskConfirmHistroty(String taskId)
	{
		ProjectOperate pop = ProjectOperateFactory.getprojectOperate();
		List result = pop.Query("Confirmhistory", "typeName,Task,typeId,"+taskId, "confirmHistoryId", "desc");
		return result ;
	}
	public List getTaskConfirmHistrotyByMakeId(String makeId){
		ProjectOperate pop = ProjectOperateFactory.getprojectOperate();
		Make make = (Make)pop.UniqueQuery("Make", "makeId,"+makeId);
		Set tasks=make.getTasks();
		List list=new ArrayList();
		for(Iterator iter=tasks.iterator();iter.hasNext();){
			Task task=(Task)iter.next();
			String taskId=String.valueOf(task.getTaskId());
			List historys = pop.Query("Confirmhistory", "typeName,Task,typeId,"+taskId, "confirmHistoryId", "desc");
			list.addAll(historys);
		}
		return list;
	}
}
